#include <game/flow/TriggerFactory.h>
#include <game/flow/Trigger.h>

#include <system/assert.h>

ARELLO_GAME_NAMESPACE_DECL_START
namespace flow {

TriggerFactory::TriggerFactory()
{ }

TriggerFactory::TriggerFactory(const TriggerFactory& rhs)
	: triggers(rhs.triggers)
{
}

TriggerFactory::~TriggerFactory()
{ }

const TriggerFactory& TriggerFactory::operator=(const TriggerFactory& rhs)
{
	if (&rhs != this)
		this->triggers = rhs.triggers;

	return *this;
}

void TriggerFactory::Register(const std::string& name, TriggerCreator creator)
{
	std::pair<std::map<std::string, TriggerCreator>::iterator, bool> insertResult =
		this->triggers.insert(std::make_pair(name, creator));

	LIBA_ASSERT(insertResult.second);
}

std::auto_ptr<Trigger> TriggerFactory::Create(const std::string& name) const
{
	std::map<std::string, TriggerCreator>::const_iterator i =
		this->triggers.find(name);

	if (i != this->triggers.end())
		return i->second();

	return std::auto_ptr<Trigger>();
}

} // namespace flow	
ARELLO_GAME_NAMESPACE_DECL_END